﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ionic.Zip;

namespace iTeachSoft.Code.Utility
{
    class ZipUtility
    {
        /// <summary>
        /// Creates a zip archive for the given directory.
        /// </summary>
        /// <param name="directoryPath">The path to the "to be archived" directory</param>
        /// <param name="targetFilePath">Destination path for the archive</param>
        public static void AddToZip(string directoryPath, string targetFilePath)
        {
            ZipFile zipArchive = new ZipFile(targetFilePath);

            zipArchive.AddDirectory(directoryPath);
            zipArchive.Save();
        }

        /// <summary>
        /// Un-zips an archive to a specified folder
        /// </summary>
        /// <param name="sourceFilePath">File path to the archive</param>
        /// <param name="targetDirectory">Directory where files will be extracted</param>
        public static void UnZip(string sourceFilePath, string targetDirectory)
        {
            ZipFile zipArchive = new ZipFile(sourceFilePath);
            zipArchive.ExtractAll(targetDirectory);
        }
    }
}
